package com.stqf.scala.grammar.funexp

/**
  * Created by ASUS on 2018-01-31.
  */
class Rational(n: Int, d: Int) {
  //println("Created:" + n + "/" + d)
  require(d != 0)
  val numer: Int = n
  val denom: Int = d

  override def toString = n + "/" + d

  def add(that: Rational): Rational = {
    new Rational(
      numer * that.denom + that.numer * denom,
      denom * that.denom
    )
  }
}
